package com.ysd.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.ysd.entity.GongSiXinXiBiao;
import com.ysd.util.DBManger;

public class GongSiXinXiBiaoDaoImpl {// 实现类 起名：实体类名+DaoImpl
	public GongSiXinXiBiao getGongSiXinXiBiao() {
		Connection conn = DBManger.getConnection();
		Statement st = null;
		ResultSet rs = null;
		GongSiXinXiBiao gsb = null;

		try {
			st = conn.createStatement();
			rs = st.executeQuery("select * from gongSiBiao");
			while (rs.next()) {
				int Id = rs.getInt("Id");
				String loGo = rs.getString("loGo");
				String name = rs.getString("name");
				String wangZhi = rs.getString("wangZhi");
				String gongSiJieShao = rs.getString("gongSiJieShao");
				String qiYeWenHua = rs.getString("qiYeWenHua");
				String gongSiDianHua = rs.getString("gongSiDianHua");
				String email = rs.getString("email");
				String gongSiDiZhi = rs.getString("gongSiDiZhi");
				gsb = new GongSiXinXiBiao(Id,loGo, name, wangZhi, gongSiJieShao, qiYeWenHua, gongSiDianHua, email,
						gongSiDiZhi);
			}
			return gsb;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		} finally {
			DBManger.closeAll(conn, st, rs);
		}
	}

	public List<GongSiXinXiBiao> getGongSiXinXiBiaoCeShi() {

		List<GongSiXinXiBiao> gsbList = new ArrayList<GongSiXinXiBiao>();
		Connection conn = DBManger.getConnection();
		Statement st = null;
		ResultSet rs = null;
		GongSiXinXiBiao gsb = null;

		try {
			st = conn.createStatement();
			rs = st.executeQuery("select * from gongSiBiao");
			while (rs.next()) {
				int Id = rs.getInt("Id");
				String loGo = rs.getString("loGo");
				String name = rs.getString("name");
				String wangZhi = rs.getString("wangZhi");
				String gongSiJieShao = rs.getString("gongSiJieShao");
				String qiYeWenHua = rs.getString("qiYeWenHua");
				String gongSiDianHua = rs.getString("gongSiDianHua");
				String email = rs.getString("email");
				String gongSiDiZhi = rs.getString("gongSiDiZhi");
				gsb = new GongSiXinXiBiao(Id,loGo, name, wangZhi, gongSiJieShao, qiYeWenHua, gongSiDianHua, email,
						gongSiDiZhi);
				gsbList.add(gsb);
			}
			return gsbList;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		} finally {
			DBManger.closeAll(conn, st, rs);
		}
	}

	public GongSiXinXiBiao getGongSiBiao(int ID) {
		Connection conn = DBManger.getConnection();
		Statement st = null; 
		ResultSet rs = null;
		GongSiXinXiBiao gsb = null;
		try {
			st=conn.createStatement();
			rs = st.executeQuery("select * from gongsibiao where Id= "+ID);
			while(rs.next()) {
					int Id = rs.getInt("Id");
					String loGo = rs.getString("loGo");
					String name = rs.getString("name");
					String wangZhi = rs.getString("wangZhi");
					String gongSiJieShao = rs.getString("gongSiJieShao");
					String qiYeWenHua = rs.getString("qiYeWenHua");
					String gongSiDianHua = rs.getString("gongSiDianHua");
					String email = rs.getString("email");
					String gongSiDiZhi = rs.getString("gongSiDiZhi");
					gsb=new GongSiXinXiBiao(Id,loGo, name, wangZhi, gongSiJieShao, qiYeWenHua, gongSiDianHua, email, gongSiDiZhi);
			}
			return gsb;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally {
			DBManger.closeAll(conn, st, rs);
		}
	
	}
	
	/**
	 * 修改公司表内容
	 */
	public int updateGSB(GongSiXinXiBiao gs) {
		String sql = "update gongsibiao set loGo='"+gs.getLoGo()+"',name ='"+gs.getName()+"',wangZhi='"+gs.getWangZhi()+"',gongSiJieShao='"+gs.getGongSiJieShao()+"',qiYeWenHua='"+gs.getQiYeWenHua()+"',gongSiDianHua='"+gs.getGongSiDianHua()+"',	email='"+gs.getEmail()+"',gongSiDiZhi='"+gs.getGongSiDiZhi()+"'	where Id="+gs.getId()+"	";
		System.out.println(sql);
		return DBManger.executeUpdate(sql);
		
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
